﻿CREATE view ErrorsGrouped as
select b.ErrorHash,b.ReleaseId,b.ErrorCount,a.ErrorType,a.ClassName,a.MethodName,
(select top 1 Message from ErrorReporting c where c.ErrorHash=b.ErrorHash) as Message,
(select top 1 StackTrace from ErrorReporting c where c.ErrorHash=b.ErrorHash) as StackTrace
from (
	select ReleaseId, ErrorHash, sum([Count]) as ErrorCount
	from ErrorReporting
	where ReleaseId = (select max(Id) from Releases where PublicReleased!=0)
	group by ReleaseId, ErrorHash
) b
inner join (
	select distinct ErrorType,ClassName,MethodName,ErrorHash
	from ErrorReporting
) a
on a.ErrorHash=b.ErrorHash
